//package xin.clips.web.aspect;
//
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.annotation.Around;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Pointcut;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//import xin.clips.common.core.domain.AjaxResult;
//import xin.clips.framework.jwt.TokenService;
//
//import javax.servlet.http.HttpServletRequest;
//import java.net.URLDecoder;
//
//@Aspect
//@Component
//public class AppAspect {
//
//    private final static Logger logger = LoggerFactory.getLogger(AppAspect.class);
//
//    @Autowired
//    private TokenService tokenService;
//
//
//    @Pointcut("execution(* xin.clips.web.controller.gy.AppUserController.*(..))")
//    public void pointcut() {
//
//    }
//
//
//    @Around(value = "pointcut()")
//    public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
//        MethodInvocationProceedingJoinPoint joinPoint = (MethodInvocationProceedingJoinPoint) proceedingJoinPoint;
//        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
//        try {
//            tokenService.verifyToken(request);
//        } catch (Exception e) {
//            return AjaxResult.error("登录失败," + e.getMessage());
//        }
//
//        String contentType = request.getContentType();
//        boolean needClear = false;
//        if ("application/x-www-form-urlencoded".equals(contentType)) {
//            needClear = true;
//        }
//        try {
//            Object[] args = joinPoint.getArgs();
//            if (needClear) {
//                for (int i = 0; i < args.length; i++) {
//                    if (args[i] instanceof String) {
//                        String decode = URLDecoder.decode((String) args[i], "UTF-8");
//                        args[i] = decode;
//                        if (((String) args[i]).endsWith("=")) {
//                            args[i] = decode.replaceAll("=", "");
//                        }
//                    }
//                }
//            }
//            Object obj = proceedingJoinPoint.proceed(args);
//            return obj;
//        } catch (Throwable throwable) {
//            return AjaxResult.error("运行异常，请联系管理员!");
//        }
//
//    }
//}
